﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using EntityInterfaces;

namespace DAL
{
    public class AuxPage : IAuxPage
    {
        private shopnetEntities model;
        private aux_pages entity;

        public String name {
            get {
                return entity.name;
            }
            set {
                entity.name = value;
            }
        }

        public String content {
            get {
                return entity.content;
            }
            set {
                entity.content = value;
            }
        }

        public int id {
            get {
                return (int)entity.auxID;
            }
        }

        public AuxPage()
        {
            model = new shopnetEntities();
        }

        public void Save()
        {
            model.aux_pages.AddObject(entity);
            try
            {
                model.SaveChanges();
            }
            catch (Exception exception)
            {
                // log
                throw new EntityException.AuxPageException("AuxPage Save error", exception);
            }
        }
        public void Read(int id)
        {
            try
            {
                entity = model.aux_pages.Single(s => s.auxID == id);
            }
            catch (Exception exception)
            {
                //log
                throw new EntityException.AuxPageException("AuxPage Read error", exception);
            }
        }
        public void Commit()
        {
            try
            {
                model.SaveChanges();
            }
            catch (Exception exception)
            {
                //log
                throw new EntityException.AuxPageException("AuxPage Commit error", exception);
            }
        }
    }
}
